import React from "react";
import ReactDom from "react-dom"

class Parent extends React.Component {
    constructor(props) {
        super(props);
        this.click = this.click.bind(this)
    }

    click(e, msg) {
        //阻止元素的默认行为
        e.preventDefault()
        console.log(e);
        alert(msg)
    }

    render() {
        return (
            <div>
                <h1>阻止元素默认行为</h1>
                <form action="http://www.baidu.com">
                    <button onClick={(e) => {this.click(e, 'hello')}}>提交</button>
                </form>
            </div>
        )
    }
}

ReactDom.render(
    <Parent/>,
    document.querySelector('#root')
)